import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        List<String> list = new ArrayList<>();
        list.add("abc");
        Class<? extends List> listClass = list.getClass();
        Method addMethod = listClass.getMethod("add", Object.class);
        addMethod.invoke(list, 10);
        System.out.println(list.size());

        for (String s: list) {
            System.out.println(s);
        }

    }

    private boolean isMatch(char[] chars, char[] pChars, int chIndex, int pIndex) {
      if (chIndex >= chars.length && pIndex < pChars.length) {
        return false;
      }
      if (pIndex >= pChars.length) {
        return true;
      }
      if (chars[chIndex] != pChars[pIndex]) {
        return false;
      }
      return isMatch(chars, pChars, chIndex + 1, pIndex + 1);
    }

    public static int kmp(String mainStr, String subString) {
        if (mainStr == null || subString == null || mainStr.length() == 0 || subString.length() == 0) {
            return -1;
        }
        char[] main = mainStr.toCharArray();
        char[] sub = subString.toCharArray();
        int[] next = getNext(sub);
        int j = 0;
        for (int i = 0; i < mainStr.length(); ++i) {
            while (j > 0 && main[i] != sub[j]) {
                j = next[j] + 1;
            }
            if (main[i] == sub[j]) {
                ++j;
            }
            //如果j==sub.length，说明模式串已经完全匹配上了，返回下标
            if (j == sub.length) {
                return i - j + 1;
            }
        }
        return -1;
    }

    private static int[] getNext(char[] sub) {
        int[] next = new int[sub.length];
        next[0] = -1;
        int k = -1;
        for (int i = 1; i < sub.length; ++i) {
            while (k != -1 && sub[k + 1] != sub[i]) {
                k = next[k];
            }
            if (sub[k + 1] == sub[i]) {
                ++k;
            }
            next[i] = k;
        }
        return next;
    }
}
